//
//  EveryViewModel.m
//  B段_开眼
//
//  Created by hu on 16/4/21.
//  Copyright © 2016年 Howie. All rights reserved.
//

#import "EveryViewModel.h"

@implementation EveryViewModel

+ (void)getDataWithPage:(NSString *)nextPage andUpdate:(BOOL)isUpdate andBlock:(void (^)(NSMutableArray *, NSString *))tableArr
{
    NSMutableArray *array = [NSMutableArray array];
    [CustomerNetWorking connectWithURL:nextPage  andUpdate:isUpdate andBlock:^(id response) {
        for (NSDictionary *dic in [response objectForKey:@"issueList"]) {
            NSMutableArray *tempArr = [NSMutableArray array];
            NSMutableDictionary *sectionDic = [NSMutableDictionary dictionary];
            for (NSDictionary *tempDic in [dic objectForKey:@"itemList"]) {
                if ([[tempDic objectForKey:@"type"] isEqualToString:@"video"]) {
                    EveryCellModel *every = [[EveryCellModel alloc] init];
                    [every setValuesForKeysWithDictionary:[tempDic objectForKey:@"data"]];
                    [tempArr addObject:every];
                } else {
                    [sectionDic setObject:[tempDic objectForKey:@"type"] forKey:@"type"];
                    [sectionDic setObject:[[tempDic objectForKey:@"data"] allValues].firstObject forKey:@"title"];
                }
            }
            [sectionDic setObject:tempArr forKey:@"array"];
            [array addObject:sectionDic];
        }

        tableArr(array, [response objectForKey:@"nextPageUrl"]);
    }];


}


@end
